﻿using System;
using System.Collections.Generic;
using System.Text;

namespace RemoveAllAdjacentDuplicatesInString
{
    public class Solution
    {
        public string RemoveDuplicates(string S)
        {
            var list = new List<char>();
            foreach (var c in S)
            {
                var peek = list.Count == 0 ? '\0' : list[list.Count - 1];
                if (peek == c)
                {
                    list.RemoveAt(list.Count - 1);
                }
                else
                {
                    list.Add(c);
                }
            }

            return string.Join("", list);
        }
    }
}
